module.exports = function($scope, $modal, $modalInstance, $resource, getDate, toaster, $timeout, Excel){

    
    var now = new Date();
    $scope.ExcelName = getDate(now);
    now.setDate(now.getDate() + 1);

    $scope.pageNum = [];
    $scope.searchDate = function(pageNo, flag){
        var para = {
			'pageNo': pageNo,
			'pageSize': 200,
			'date': getDate(now)
        }
        $resource('/api/as/ggc/order/getTodayList', {}, {}).save(para, function(res){
            if (res.errcode === 0){
                if(res.data.length != 0){
                    $scope.downList = res.data.results;
                    if($scope.pageNum.length == 0){
                        for(var i = 1; i <= res.data.totalPage; i++){
                            $scope.pageNum.push({'num': i, 'id': 'dlink' + i});
                        }
                    }
                    if(flag){
                        $scope.exportToExcel('#Excel_table', pageNo);
                    }
                } else {
                    toaster.error({title: '', body: '今天没人报名, 导不出来'});
                }
            } else {
                toaster.error({title: '', body: '导出人员名单失败'});
            }
        });
    }
    $scope.searchDate(1, false);

    $scope.download= function(pageNo){
        if(pageNo == 1){
            $scope.exportToExcel('#Excel_table', pageNo);
        } else {
            $scope.searchDate(pageNo, true);
        }
    }

    //导出当天跟团游的人员名单
    
    $scope.exportToExcel = function (tableId, pageNo){
        $timeout(function(){
            var dlink = document.getElementById("dlink" + pageNo);
            dlink.href = Excel.tableToExcel(tableId, 'sheet1');
            dlink.click();
        }, 100);
    }

    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    }


};